package br.com.trophy.parsing;

import java.net.URL;
import java.util.Vector;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

public class ParsingTrophies
{
	public static Vector<Trophy> getTrophies( String user, String gameId )
	{
		Vector<Trophy> conteudoXML = null;
		try
		{
			// endereco do XML
			URL url = new URL( "http://mypst.com.br/rank/" + user + "/jogo/"
					+ gameId + "/xml/" );

			// SAXParser
			SAXParserFactory spf = SAXParserFactory.newInstance();
			SAXParser sp = spf.newSAXParser();

			// XMLReader
			XMLReader xr = sp.getXMLReader();

			// Novo Handler, de acordo com o criado, no caso JogosHandler
			TrophyHandler handler = new TrophyHandler();
			xr.setContentHandler( handler );

			InputSource input = new InputSource( url.openStream() );

			// Realizando o parse de acordo com a URL
			xr.parse( input );

			conteudoXML = handler.getParsedTrophies();
			return conteudoXML;
		}
		catch ( Exception e )
		{
		}
		return conteudoXML;
	}
}
